package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Emp;
import com.itheima.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmpMapper empMapper;

    //pageHelper 改造注释以前的。
//    public List<Emp> getList(Integer page,Integer pageSize){
//        return empMapper.getList((page-1)*pageSize,pageSize);
//    }
//
//    public Long getCout(){
//        return empMapper.getCout();
//    }

    private Page pg;

    public List<Emp>  getList(Integer page, Integer PageSize, String name, Short gender, LocalDate begin, LocalDate end){

        System.out.println("service 参数"+name);
        System.out.println("service 参数"+gender);
        System.out.println("service 参数"+begin);
        System.out.println("service 参数"+end);

        this.pg=PageHelper.startPage(page,PageSize);//设置起始参数后

        empMapper.getList(name, gender, begin,end);  //然后正常查询

//        List<Emp> emps=(Page<Emp>)this.pg;
        return (List<Emp>)this.pg.getResult();

    }

    public Long getCout(){
        return  this.pg.getTotal();
    }

    public void deletes(List<Integer> ids){
        empMapper.deletes(ids);
    }
}
